package com.finance.rule.request;

import com.finance.base.constant.PatternConstants;
import com.finance.framework.lang.valid.EnumValid;
import com.finance.util.DateUtil;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import javax.validation.constraints.Pattern;
import java.text.ParseException;
import java.util.Date;

/**
 * @Author: gly
 * @Date: Created in 2017-07-27
 */
@Data
public class WeightRangeImportReq {
    /**
     *供货商编码
     * */
    @Length(max=20,message = "供货商编码长度小于20")
    @NotBlank(message = "供货商名称不能为空且名称不能有误")
    private String supplierCode;

    /**
     *运单配送类型 枚举 0配送 1上门换 2上门退
     * */
    @EnumValid(enums = {"0","1","2"},message = "运单配送类型枚举型")
    @NotBlank(message = "配送类型不能为空且名称不能有误")
    private String direction;

    /**
     *结算区域ID 参考结算区域表
     * */
    @Length(max = 18,message = "结算区域ID不能超过18位")
    @Pattern(regexp = PatternConstants.PATTERN_NUMBER,message = "结算区域ID数值型")
    @NotBlank(message = "结算区域不能为空且名称不能有误")
    private String regionId;

    /**
     *左边界数字
     * */
    @Length(max = 11,message = "左边界数字不能超过11位")
    @Pattern(regexp = PatternConstants.PATTERN_NUMBER_TWO_DECIMAL_POINT,message = "左边界数字最多两位小数")
    @NotBlank(message = "左边界数字不能为空")
    private String pointLeft;

    /**
     *是否包含边界数字 0表示值大于point_left 1表示值不小于point_left
     * */
    @EnumValid(enums = {"0","1"},message = "包含左边界数字枚举型")
    @NotBlank(message = "包含左边界数字不能为空且名称不能有误")
    private String containLeft;

    /**
     *右边界数字
     * */
    @Length(max = 11,message = "右边界数字不能超过11位")
    @Pattern(regexp = PatternConstants.PATTERN_NUMBER_TWO_DECIMAL_POINT,message = "右边界数字最多两位小数")
    @NotBlank(message = "右边界数字不能为空")
    private String pointRight;

    /**
     *是否包含边界数字 0表示值小于point_right 1表示值不大于point_right
     * */
    @EnumValid(enums = {"0","1"},message = "包含右边界数字枚举型")
    @NotBlank(message = "包含右边界数字不能为空且名称不能有误")
    private String containRight;

    /**
     *首重值 优先级高于边界值
     * */
    @Length(max = 11,message = "首重值不能超过11位")
    @Pattern(regexp = PatternConstants.PATTERN_NUMBER_TWO_DECIMAL_POINT,message = "首重值最多两位小数")
    private String fixWeight;


    /**
     *首重单价 单位元
     * */
    @Length(max = 11,message = "首重单价不能超过11位")
    @Pattern(regexp = PatternConstants.PATTERN_NUMBER_TWO_DECIMAL_POINT,message = "首重单价最多两位小数")
    @NotBlank(message = "首重单价不能为空")
    private String firstPrice;

    /**
     *续重单价 单位元
     * */
    @Length(max = 11,message = "续重单价不能超过11位")
    @Pattern(regexp = PatternConstants.PATTERN_NUMBER_TWO_DECIMAL_POINT,message = "续重单价最多两位小数")
    @NotBlank(message = "续重单价不能为空")
    private String secondPrice;

    /**
     * 是否含待收款
     */

    @EnumValid(enums = {"0","1"},message = "是否含待收款枚举")
    @NotBlank(message = "是否含代收款不能为空且名称不能有误")
    private String cod;

    /**
     *规则快照 规则变化后 系统现用的有限规则会备份到此字段
     * */
    private String snapshot;

    private String startTime;

    private String endTime;

    private String supplierCodeImport;

    private String directionImport;

    private String regionImport;

    private String containLeftImport;

    private String containRightImport;

    private String codImport;

    public Date convertStartTime() throws ParseException {
        if(this.startTime!=null){
            return DateUtil.str2date(this.startTime);
        }
        return null;
    }
    public Date convertEndTime() throws ParseException {
        if(this.endTime!=null){
            return DateUtil.str2date(this.endTime);
        }
        return null;
    }

}
